export default {
	data() {
		return {
			listStyle: '',
			loadingType: 'loading', //加载更多状态
			orderType: '',
			priceOrder: 'desc', //1 价格从低到高 2价格从高到低
			categoryList: [], //排序类型
			order: '',
			sort: 'desc',
			showScreen: false,
			keyword: '',
			categoryId: 0,
			minPrice: '',
			maxPrice: '',
			isFreeShipping: false, //是否免邮
			isIphoneX: false,
			coupon: 0,
			emptyShow: false,
			isList: true ,//列表样式
			goodsList:[], //商品搜索数据源
			notesList:[] ,//笔记搜索数据
			lastPage: 1,
			currentPage: 1,
			status: 'loadmore',
			showEmpty: false
		}
	},

	onLoad(options) {
		this.keyword = options.keyword || '';
		this.isIphoneX = this.$util.uniappIsIPhoneX();
		this.getSearchlist();
	},
	onShow() {
		// 刷新多语言
		this.$langConfig.refresh();
	},
	onReachBottom() {
		if (this.currentPage < this.lastPage) {
			this.currentPage += 1;
			this.getSearchlist();
		}
	},
	methods: {
		getSearchlist() {
			this.loadStatus = 'loading';
			this.$api.sendRequest({
				url: '/api/search/search',
				data: {
					page: this.currentPage,
					keyword: this.keyword
				},
				success: res => {
					if (res.code == 0) {
						//查询结果数据
						this.goodsList = [...this.goodsList, ...res.goods.data];
						this.notesList = [...this.notesList, ...res.notes.data];
						//商品查询结果列表分页
						this.lastPage = res.goods.last_page;
						this.isEmpty = !this.goodsList.length;
						this.loadStatus = this.currentPage < res.goods.last_page ? 'loadmore' : 'nomore';
						//笔记查询结果列表分页
						this.lastPage = res.notes.last_page;
						this.isEmpty = !this.notesList.length;
						this.loadStatus = this.currentPage < res.notes.last_page ? 'loadmore' : 'nomore';
						
					}
				},
				fail: res => {
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
			
		changeListStyle() {
			this.isList = !this.isList
		},
		//加载分类
		loadCategoryList(fid, sid) {
			this.$api.sendRequest({
				url: '/api/goodscategory/tree',
				data: {},
				success: res => {
					if (res.data != null) this.categoryList = res.data;
				}
			});
		},

		//商品详情
		toDetail(item) {
			this.$util.redirectTo('/goods/detail/detail', {
				sku_id: item.sku_id
			});
		},
		//笔记详情
		toNotes(item) {
			this.$util.redirectTo('/otherpages/store_notes/note_detail/note_detail', {
				note_id: item.note_id
			});
			
		},
		search() {
			this.goodsList = [];
			this.notesList = [];
			this.getSearchlist();
		},
		goodsImg(imgStr) {
			let imgs = imgStr.split(',');
			return imgs[0] ? this.$util.img(imgs[0], {
				size: 'mid'
			}) : this.$util.getDefaultImage().default_goods_img;
		},
		imgError(index) {
			this.goodsList[index].goods_image = this.$util.getDefaultImage().default_goods_img;
		},
		showPrice(data) {
			let price = data.discount_price;
			if (data.member_price && parseFloat(data.member_price) < parseFloat(price)) price = data.member_price;
			return price;
		}
	}

}
